package com.example.demo.project.utils;

import com.example.demo.project.sys.SysCommon;


import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateUtils {

	public final static int HOURS_PER_DAY = 24;

	public final static long ONE_SECOND_MS = 1000;
	public final static long ONE_MINUTE_MS = ONE_SECOND_MS * 60;
	public final static long ONE_HOUR_MS = ONE_MINUTE_MS * 60;
	public final static long ONE_DAY_MS = ONE_HOUR_MS * HOURS_PER_DAY;
	
	public final static String[] NO_UPPER_CASE = new String[] {"○", "一", "二", "三","四","五","六","七","八","九"};

	public final static WorkDayCounter WORK_DATE_UTILS = WorkDayCounter.getDefault();

	public static Calendar getCalendar(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c;
	}

    public static Date dateAddWorkDay(Date start, Integer days){
        if(start==null || days==null) return null;
        Calendar d1 = Calendar.getInstance();
        Calendar d2 = Calendar.getInstance();
        d1.setTime(start);
        d2.setTime(start);
        while(days>0){
        	d2.add(Calendar.DAY_OF_YEAR, 1);
            if(d2.get(Calendar.DAY_OF_WEEK)== Calendar.SATURDAY || d2.get(Calendar.DAY_OF_WEEK)== Calendar.SUNDAY){
            	d2.add(Calendar.DAY_OF_YEAR, 1);
            }else{
                days --;
            }
        }
        return d2.getTime();
    }
    public static Date dateAddWorkDay2(Date start, Integer days){
    	if(start==null || days==null) return null;
    	Calendar d1 = Calendar.getInstance();
    	Calendar d2 = Calendar.getInstance();
    	d1.setTime(start);
    	d2.setTime(start);
    	d2.add(Calendar.DAY_OF_YEAR, -1);
    	while(days>0){
    		d2.add(Calendar.DAY_OF_YEAR, 1);
    		if(d2.get(Calendar.DAY_OF_WEEK)== Calendar.SATURDAY || d2.get(Calendar.DAY_OF_WEEK)== Calendar.SUNDAY){
    			d2.add(Calendar.DAY_OF_YEAR, 1);
    		}else{
    			days --;
    		}
    	}
    	return d2.getTime();
    }
    /**求加上某个天数之后的日期**/
    public static Date dateAddDay(Date start, Integer days){
    	if(start==null || days==null) return null;
    	Calendar d = Calendar.getInstance();
    	if(days > 0) days --;
    	d.add(Calendar.DAY_OF_YEAR, days);
    	return d.getTime();
    }

    /**
	 * 计算两个日期之间的工作日数，结果永远是正数
	 * @param beginDate
	 * @param endDate
	 * @return
	 */
	public static int countWorkDay(Date beginDate, Date endDate) {
		Calendar d1 = Calendar.getInstance();
		Calendar d2 = Calendar.getInstance();
		d1.setTime(beginDate.before(endDate) ? beginDate : endDate);
		d2.setTime(beginDate.after(endDate) ? beginDate : endDate);
        int days = (int) ((d2.getTimeInMillis() - d1.getTimeInMillis())/ONE_DAY_MS);
		int cycTimes = days / Calendar.DAY_OF_WEEK;
		int lessDays = days % Calendar.DAY_OF_WEEK;
		int workDays = cycTimes * 5 + lessDays;
		for (; lessDays > 0; lessDays--) {
			if (d2.get(Calendar.DAY_OF_WEEK) % Calendar.DAY_OF_WEEK < 2) {
				workDays--;
			}
			d2.add(Calendar.DAY_OF_YEAR, -1);
		}
		return workDays;
	}

	private static boolean isWorkDay(Calendar date) {
		int bd = date.get(Calendar.DAY_OF_WEEK);
		return (1 == bd || 7 == bd);
	}

	/**
	 * 计算两个日期之间的工作日数
	 * @param beginDate
	 * @param endDate
	 * @return
	 */
	public static int countWorkDay2(Date beginDate, Date endDate) {
		boolean asc = beginDate.before(endDate);
		Calendar d1 = Calendar.getInstance();
		Calendar d2 = Calendar.getInstance();
		d1.setTime(asc ? beginDate : endDate);
		d2.setTime(!asc ? beginDate : endDate);
		int days = (int) ((d2.getTimeInMillis() - d1.getTimeInMillis())/ONE_DAY_MS);
		int cycle = days / Calendar.DAY_OF_WEEK;
		int lessDays = days % Calendar.DAY_OF_WEEK;
		int workDays = cycle * 5 + (isWorkDay(d1) ? 0 : 1);

		d1.add(Calendar.DAY_OF_YEAR, days - lessDays);
		for (; lessDays > 0; lessDays--) {
			d1.add(Calendar.DAY_OF_WEEK, 1);
			if (!isWorkDay(d1)) {
				workDays += 1;
			}
		}
		return asc ? workDays : -workDays;
	}

	/**
	 * 获取两段时间范围的交集内的时间
	 * @param b1
	 * @param e1
	 * @param b2
	 * @param e2
	 * @return
	 */
	public static long intersection(Date b1, Date e1, Date b2, Date e2) {
		if (null == b1 && null == b2) throw new IllegalArgumentException();
		if (null == e2 && null == e2) throw new IllegalArgumentException();
		Date b, e;
		if (null == b1) b = b2; else if (null == b2) b = b1; else b = b1.before(b2) ? b2 : b1;
		if (null == e1) e = e2; else if (null == e2) e = e1; else e = e1.before(e2) ? e1 : e2;
		if (b.before(e)) {
			return e.getTime() - b.getTime();
		}
		return 0;
	}

	public static Calendar getWithoutTimeInfo(Date date) {
		Calendar startDateInfo = Calendar.getInstance();
		startDateInfo.setTime(date);
		startDateInfo.set(Calendar.HOUR_OF_DAY, 0);
		startDateInfo.set(Calendar.MINUTE, 0);
		startDateInfo.set(Calendar.SECOND, 0);
		startDateInfo.set(Calendar.MILLISECOND, 0);
		return startDateInfo;
	}

	public static boolean isSameDay(Calendar start, Calendar end) {
		return start.get(Calendar.YEAR) == end.get(Calendar.YEAR)
				&& start.get(Calendar.MONTH) == end.get(Calendar.MONTH) && start.get(Calendar.DAY_OF_MONTH) == end.get(Calendar.DAY_OF_MONTH);
	}

	public static void main(String[] args) throws Exception {
		/*Calendar d1 = Calendar.getInstance();
		Calendar d2 = Calendar.getInstance();
		d1.set(Calendar.YEAR, 2015);
		d1.set(Calendar.MONTH, 5);
		d1.set(Calendar.DAY_OF_MONTH, 27);

		d2.set(Calendar.YEAR, 2015);
		d2.set(Calendar.MONTH, 5);
		d2.set(Calendar.DAY_OF_MONTH, 26);
		
		long[] result = compara(d1.getTime(), d2.getTime());
		System.out.println(result.toString());*/

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		System.out.println(sdf.format(tomorrow().getTime()));
	}

	/**
	 * 返回两个日期对象的时间差信息
	 * @param beginDate
	 * @param endDate
	 * @return
	 */
	public static long[] compara(Date beginDate, Date endDate) {
		long delay = Math.abs(endDate.getTime() - beginDate.getTime());
		long[] delayInfo = new long[5];
		delayInfo[0] = delay / ONE_DAY_MS;
		long less1 = delay % ONE_DAY_MS;
		delayInfo[1] = less1 / ONE_HOUR_MS;
		long less2 = less1 % ONE_HOUR_MS;
		delayInfo[2] = less2 / ONE_MINUTE_MS;
		long less3 = less2 % ONE_MINUTE_MS;
		delayInfo[3] = less3 / ONE_SECOND_MS;
		long less4 = less3 % ONE_SECOND_MS;
		delayInfo[4] = less4;
		return delayInfo;
	}
	
	/**
	 * 返回两个日期对象的时间差信息，以字符串的形式表示。
	 * @param beginDate
	 * @param endDate
	 * @return
	 */
	public static String comparaAsString (Date beginDate, Date endDate) {
		long[] di = DateUtils.compara(beginDate, endDate);
		String r = String.format("%1$d天%2$d小时%3$d分钟%4$d秒", di[0], di[1], di[2], di[3]);
		return r.replaceAll("0\\D+(?=\\d)", "");
	}
	
	/**
	 * 获取某日期所处周的开始日期和结束日期
	 * @param date
	 * @return
	 */
	public static Date[] getWeekRange(Date date) {
		
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.set(Calendar.HOUR, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		c.set(Calendar.MILLISECOND, 0);
		date = c.getTime();
		
		int weekIndex = c.get(Calendar.DAY_OF_WEEK);
		
		Calendar b = Calendar.getInstance();
		b.setTime(date);
		b.add(Calendar.DATE, -weekIndex + 1);
		
		Calendar e = Calendar.getInstance();
		e.setTime(date);
		e.add(Calendar.DATE, 7-weekIndex);
		return new Date[]{b.getTime(), e.getTime()};
	}
	
	/**
	 * 获取某日期上周的开始日期和结束日期
	 * @param date
	 * @return
	 */
	public static Date[] getLastWeekRange(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.add(Calendar.DAY_OF_YEAR, -6);
		return getWeekRange(c.getTime());
	}
	
	
	/**
	 * 获取指定日期的年份
	 * @param date
	 * @return
	 */
	public static int getYear(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.YEAR);
	}
	
	/**
	 * 获取指定日期的月份
	 * @param date
	 * @return
	 */
	public static int getMonth(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.MONTH) + 1;
	}
	
	
	/**
	 * 获得指定日期在本年的第几天
	 * @return
	 */
	public static int getDayOfYear(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.DAY_OF_YEAR);
	}
	
	/**
	 * 获得指定日期在本周的第几天
	 * @return
	 */
	public static int getDayOfWeek(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.DAY_OF_WEEK);
	}

	/**
	 * 日期转大写的年月日表达式。
	 * @param date
	 * @return
	 */
	public static String upperCase(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		
		StringBuilder sb = new StringBuilder();
		
		String year = String.valueOf(c.get(Calendar.YEAR));
		for (int i = 0; i < year.length(); i++) {
			sb.append(NO_UPPER_CASE[year.charAt(i) - '0']);
		}
		sb.append("年");
		
		String month = String.valueOf(c.get(Calendar.MONTH) + 1);
		if (1 < month.length()) {
			sb.append(('1' == month.charAt(0) ? "" : NO_UPPER_CASE[month.charAt(0) - '0']) + "十");
			sb.append(NO_UPPER_CASE[month.charAt(1) - '0']);
		} else {
			sb.append(NO_UPPER_CASE[month.charAt(0) - '0']);
		}
		sb.append("月");
		
		String day = String.valueOf(c.get(Calendar.DAY_OF_MONTH));
		if (1 < day.length()) {
			sb.append(('1' == day.charAt(0) ? "" : NO_UPPER_CASE[day.charAt(0) - '0']) + "十");
			sb.append(NO_UPPER_CASE[day.charAt(1) - '0']);
		} else {
			sb.append(NO_UPPER_CASE[day.charAt(0) - '0']);
		}
		sb.append("日");
		
		return sb.toString();
	}
	/*
	 * 比较时间
	 */
	public static boolean compareDateAfter(Date dateAfter, Date date, SimpleDateFormat adf){
		boolean flag = false;
		try {
		String date1 =  adf.format(dateAfter);
		String date2 =  adf.format(date);
		if(adf.parse(date1).before(adf.parse(date2)) || adf.parse(date1).equals((adf.parse(date2)))){
			flag = true;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
		
	}

	
	/**
	 * 获取某年某月第一天
	 * 
	 * @return
	 */
	public static String getFirstDayOfMonth(Date date) {
		String str = "";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar lastDate = Calendar.getInstance();
		lastDate.setTime(date);
		lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
		str = sdf.format(lastDate.getTime());
		return str;
	}
	
	/**
	 * 计算某年某月最后一天,返回字符串
	 * 
	 * @return
	 */
	public static String getLastDayOfMonth(Date date) {
		String str = "";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar lastDate = Calendar.getInstance();
		lastDate.setTime(date);
		lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
		lastDate.add(Calendar.MONTH, 1);// 加一个月，变为下月的1号
		lastDate.add(Calendar.DATE, -1);// 减去一天，变为当月最后一天
		str = sdf.format(lastDate.getTime());
		return str;
	}
	
	/**
	 * 获取某年某月的最后一天
	 * 
	 * @param year
	 *            年
	 * @param month
	 *            月
	 * @return 最后一天
	 */
	public static int getLastDayOfMonth(int year, int month) {
		if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
				|| month == 10 || month == 12) {
			return 31;
		}
		if (month == 4 || month == 6 || month == 9 || month == 11) {
			return 30;
		}
		if (month == 2) {
			if (isLeapYear(year)) {
				return 29;
			} else {
				return 28;
			}
		}
		return 0;
	}
	
	/**
	 * 是否闰年
	 * 
	 * @param year
	 *            年
	 * @return
	 */
	public static boolean isLeapYear(int year) {
		return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
	}
	
	
    public static Date max(Date date1, Date date2) {
        if (null == date1) return date2;
        if (null == date2) return date1;
        if (date1.after(date2)) return date1;
        return date2;
    }
    /**
     * 
     * @param year
     * @param month 从0开始,0代表1月
     * @return
     */
    public static Date[] getMonthStartAndEnd(int year, int month){
    	Date[] dates = new Date[2];
    	Calendar date = Calendar.getInstance();
    	date.set(year, month, 1, 0, 0, 0);
    	date.set(Calendar.MILLISECOND, 0);
    	dates[0] = date.getTime();
//    	date.set(year, month,getLastDayOfMonth(year,month+1),23,59,59);
    	date.add(Calendar.MONTH, 1);
    	date.add(Calendar.MILLISECOND, -1);
    	dates[1] = date.getTime();
    	return dates;
    }

	public static Calendar combineDatePartAndTimePart(Calendar datePart, Calendar timePart) {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.YEAR, datePart.get(Calendar.YEAR));
		c.set(Calendar.MONTH, datePart.get(Calendar.MONTH));
		c.set(Calendar.DAY_OF_YEAR, datePart.get(Calendar.DAY_OF_YEAR));
		c.set(Calendar.HOUR, timePart.get(Calendar.HOUR));
		c.set(Calendar.MINUTE, timePart.get(Calendar.MINUTE));
		c.set(Calendar.SECOND, timePart.get(Calendar.SECOND));
		c.set(Calendar.MILLISECOND, timePart.get(Calendar.MILLISECOND));
		return c;
	}

	public static Calendar combineDatePartAndTimePart(Calendar datePart, String timePart) {
		try {
			Date date = SysCommon.YMD_HMS.parse(SysCommon.YMD.format(datePart.getTime()) + " " + timePart);
			return DateUtils.getCalendar(date);
		} catch (Exception e) {
			throw new IllegalStateException(e);
		}

		/*String[] args = timePart.split(":");
		Calendar c = Calendar.createOrGet();
		c.set(Calendar.YEAR, datePart.get(Calendar.YEAR));
		c.set(Calendar.MONTH, datePart.get(Calendar.MONTH));
		c.set(Calendar.DAY_OF_YEAR, datePart.get(Calendar.DAY_OF_YEAR));
		c.set(Calendar.HOUR, Integer.parseInt(args[0]));
		c.set(Calendar.MINUTE, Integer.parseInt(args[1]));
		c.set(Calendar.SECOND, Integer.parseInt(args[2]));
		if (3 < args.length) {
			c.set(Calendar.MILLISECOND, Integer.parseInt(args[3]));
		} else {
			c.set(Calendar.MILLISECOND, 0);
		}
		return c;
		*/
	}
	public static double countMinutes(Date beginTime, Date endTime) {
		return BigDecimal.valueOf((endTime.getTime() - beginTime.getTime()))
				.divide(BigDecimal.valueOf(ONE_MINUTE_MS), 1, BigDecimal.ROUND_HALF_UP).doubleValue();
	}
	public static double countHours(Date beginTime, Date endTime) {
		return BigDecimal.valueOf((endTime.getTime() - beginTime.getTime()))
				.divide(BigDecimal.valueOf(ONE_HOUR_MS), 1, BigDecimal.ROUND_HALF_UP).doubleValue();
	}
	public static double countHours(String beginTime, String endTime) {
		Calendar now = Calendar.getInstance();
		Calendar b = combineDatePartAndTimePart(now, beginTime);
		Calendar e = combineDatePartAndTimePart(now, endTime);
		return BigDecimal.valueOf((e.getTime().getTime() - b.getTime().getTime())).divide(BigDecimal.valueOf(ONE_HOUR_MS), 1, BigDecimal.ROUND_HALF_UP).doubleValue();
	}

	/**
	 *  获取两个日期相差的月数
	 * @param d1    较大的日期
	 * @param d2    较小的日期
	 * @return  如果d1>d2返回 月数差 否则返回0
	 */

	public static int getMonthDiff(Date d1, Date d2) {
		Calendar c1 = Calendar.getInstance();
		Calendar c2 = Calendar.getInstance();
		c1.setTime(d1);
		c2.setTime(d2);
		if(c1.getTimeInMillis() < c2.getTimeInMillis()) return 0;
		int year1 = c1.get(Calendar.YEAR);
		int year2 = c2.get(Calendar.YEAR);
		int month1 = c1.get(Calendar.MONTH);
		int month2 = c2.get(Calendar.MONTH);
		int day1 = c1.get(Calendar.DAY_OF_MONTH);
		int day2 = c2.get(Calendar.DAY_OF_MONTH);
		// 获取年的差值 假设 d1 = 2015-8-16  d2 = 2011-9-30
		int yearInterval = year1 - year2;
		// 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数
		if(month1 < month2 || month1 == month2 && day1 < day2) yearInterval --;
		// 获取月数差值
		int monthInterval =  (month1 + 12) - month2  ;
		if(day1 < day2) monthInterval --;
		monthInterval %= 12;
		return yearInterval * 12 + monthInterval;
	}

	public static Calendar toCalendar(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c;
	}

    public static Date now() {
		return new Date();
    }

    public static Calendar dateOnly(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		c.set(Calendar.MILLISECOND, 0);
		return c;
	}

	public static Calendar today() {
		return dateOnly(now());
	}

	public static Calendar tomorrow(Date... starDate) {
		Calendar today = dateOnly((0 == starDate.length) ? now() : starDate[0]);
		today.add(Calendar.DATE, 1);
		return today;
	}

	public static Calendar firstDayOfMonth() {
		Calendar c = today();
		c.set(Calendar.DAY_OF_MONTH, 1);
		return c;
	}

	public static Calendar firstDayOfYear() {
		Calendar c = today();
		c.setTime(DateUtils.now());
		c.set(Calendar.DAY_OF_YEAR, 1);
		return c;
	}

    public static Integer getCurrentYear() {
		Calendar c = Calendar.getInstance();
		c.setTime(DateUtils.now());
		return c.get(Calendar.YEAR);
	}

	public static Integer getCurrentMonth() {
		Calendar c = Calendar.getInstance();
		c.setTime(DateUtils.now());
		return c.get(Calendar.MONTH) + 1;
	}

	public static Integer[] getCurrentYearAndMonth() {
		Calendar c = Calendar.getInstance();
		c.setTime(DateUtils.now());
		return new Integer[]{c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1};
	}

	public static int countDays(Date beginDate, Date endDate) {
		Calendar d1 = DateUtils.dateOnly(beginDate);
		Calendar d2 = DateUtils.dateOnly(endDate);
		d2.add(Calendar.DAY_OF_YEAR, 1);
		int days = (int) ((d2.getTimeInMillis() - d1.getTimeInMillis()) / ONE_DAY_MS);
		return days;
	}

	@SuppressWarnings("static-access")
	public static Date getLaterMonthDate(Date date, int i) {
		Calendar calendar = new GregorianCalendar();
	    calendar.setTime(date);
	    System.out.println(calendar.MONTH);
	    calendar.add(calendar.MONTH, 1);//把日期往后增加一个月.整数往后推,负数往前移动
	    date = calendar.getTime();   //这个时间就是日期往后推一天的结果
	    return date;
	}
	public static Date getFirstDayOfWeek(Date date) {
		Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
		int dayWeek = calendar.get(Calendar.DAY_OF_WEEK);
        if (1 == dayWeek) {
            calendar.add(Calendar.DAY_OF_MONTH, -1);
        }
        calendar.setFirstDayOfWeek(Calendar.MONDAY);// 设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
        int dayMon = calendar.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
        calendar.add(Calendar.DATE, calendar.getFirstDayOfWeek() - dayMon);// 根据日历的规则，给当前日期减去星期几与一个星期第一天的差值
		return calendar.getTime();
	}

	public static Date getlastDayOfWeek(Date date) {
		Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
		int dayWeek = calendar.get(Calendar.DAY_OF_WEEK);
        if (1 == dayWeek) {
            calendar.add(Calendar.DAY_OF_MONTH, -1);
        }
        calendar.setFirstDayOfWeek(Calendar.MONDAY);// 设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
        int day = calendar.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
        int first = calendar.getFirstDayOfWeek();
        calendar.add(Calendar.DAY_OF_WEEK, first - day + 4); // 计算周五的日期
        return calendar.getTime();
	}

	/**
	 * 计算两个日期相差天数
	 */
	public static int differentDays(Date date1, Date date2) {
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(date1);
		Calendar cal2 = Calendar.getInstance();
		cal2.setTime(date2);
		int day1 = cal1.get(Calendar.DAY_OF_YEAR);
		int day2 = cal2.get(Calendar.DAY_OF_YEAR);

		int year1 = cal1.get(Calendar.YEAR);
		int year2 = cal2.get(Calendar.YEAR);
		if (year1 != year2) {
			// 同一年
			int timeDistance = 0;
			for (int i = year1; i < year2; i++) {
				if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
					// 闰年
					timeDistance += 366;
				} else {
					// 不是闰年
					timeDistance += 365;
				}
			}
			return timeDistance + (day2 - day1);
		} else {
			// 不同年
			return day2 - day1;
		}
	}

	public static BigDecimal differentDaysByMillisecond(Date beforeDate, Date nowDate) {
		BigDecimal hours = BigDecimal.valueOf(nowDate.getTime() - beforeDate.getTime()).divide(BigDecimal.valueOf(DateUtils.ONE_HOUR_MS), 2, BigDecimal.ROUND_HALF_UP);
		BigDecimal days = hours.divide(BigDecimal.valueOf(24), 4, BigDecimal.ROUND_DOWN);
		return days;
	}
	/**
	 * 指定日期加指定天数
	 */
	@SuppressWarnings("static-access")
	public static Date getAddDate(Date date, BigDecimal days){
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		calendar.add(calendar.DATE, 1);// 把日期往后增加一天.整数往后推,负数往前移动
		return calendar.getTime();
	}
	/*public static Date getFirstDayOfWeek(Date date) {
		Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
		int dayWeek = calendar.get(Calendar.DAY_OF_WEEK);
        if (1 == dayWeek) {
            calendar.add(Calendar.DAY_OF_MONTH, -1);
        }
        calendar.setFirstDayOfWeek(Calendar.MONDAY);// 设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
        int dayMon = calendar.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
        calendar.add(Calendar.DATE, calendar.getFirstDayOfWeek() - dayMon);// 根据日历的规则，给当前日期减去星期几与一个星期第一天的差值
		return calendar.getTime();
	}*/

/*	public static Date getlastDayOfWeek(Date date) {
		Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
		int dayWeek = calendar.get(Calendar.DAY_OF_WEEK);
        if (1 == dayWeek) {
            calendar.add(Calendar.DAY_OF_MONTH, -1);
        }
        calendar.setFirstDayOfWeek(Calendar.MONDAY);// 设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
        int day = calendar.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
        int first = calendar.getFirstDayOfWeek();
        calendar.add(Calendar.DAY_OF_WEEK, first - day + 4); // 计算周五的日期
        return calendar.getTime();
	}*/

	/**
	 * 计算两个日期相差天数
	 */
	/*public static int differentDays(Date date1, Date date2) {
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(date1);
		Calendar cal2 = Calendar.getInstance();
		cal2.setTime(date2);
		int day1 = cal1.get(Calendar.DAY_OF_YEAR);
		int day2 = cal2.get(Calendar.DAY_OF_YEAR);

		int year1 = cal1.get(Calendar.YEAR);
		int year2 = cal2.get(Calendar.YEAR);
		if (year1 != year2) {
			// 同一年
			int timeDistance = 0;
			for (int i = year1; i < year2; i++) {
				if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
					// 闰年
					timeDistance += 366;
				} else {
					// 不是闰年
					timeDistance += 365;
				}
			}
			return timeDistance + (day2 - day1);
		} else {
			// 不同年
			return day2 - day1;
		}
	}*/
}
